<?php namespace web\admin\controller;
/**
 * Created by PhpStorm.
 * User: qianchenmiao
 * Date: 2016/10/10
 * Time: 17:54
 */
class Goodslist extends  Common{

	public function index(){
		$model=new \system\model\GoodsList();
		if(IS_POST){

			if($model->store()){

				message('添加成功',u('index',['gid'=>$_POST['gid']]),'success');
			}

			message($model->getError(),'','error');
		}
//		获取添加所需的数据
		$gid=q('get.gid',0,'intval');
		$tid=Db::table('goods')->where('gid',$gid)->pluck('tid');
//		获取类型属性中的规格名称和taid
		$data=Db::table('type_attr')->where('class',2)->where('tid',$tid)->get();
//			通过taid去商品属性表查找该商品的所有规格属性
		foreach($data as $k=>$v){
			$data[$k]['select']=Db::table('goods_attr')->where('taid',$v['taid'])->where('gid',$gid)->get();
		}
		View::with('data',$data);
//		获取商品属性表的数据在页面中遍历出来
		$ListData=$model->where('gid',$gid)->get();
		foreach($ListData as $k=>$v){
			$ListData[$k]['combine']=explode('|',$v['combine']);
			foreach($ListData[$k]['combine'] as $kk=>$vv){
				$ListData[$k]['combine'][$kk]=Db::table('goods_attr')->where('gaid',$vv)->pluck('gavalue');
			}
		}


		View::with('ListData',$ListData)->make();

	}
	public  function del(){
		$glid=q('get.glid',0,'intval');
$gid=q('get.gid',0,'intval');

		$v=Db::table('goods_list')->where('glid',$glid)->delete();
		if($v){
			message('删除成功',u('index',['gid'=>$gid]),'success');
		}

	}
}